<template>
  <div class="home-view">
    <div class="profile">
      <div class="user-info">
        <el-avatar :src="userImg" :size="100" class="avatar"></el-avatar>
      </div>
      <div class="info">
        <p>你好，{{ displayUsername }}。生活就像海洋，只有意志坚强的人才能到达彼岸！</p>
      </div>
    </div>
    <div class="menu">
      <router-link v-for="item in menulist" :key="item.path" :to="item.path" class="fast-button">
        <el-icon>
          <component :is="item.icon"></component>
        </el-icon>
        <span>{{ item.label }}</span>
      </router-link>
    </div>
    <div class="user-info">
      <router-link to="/user/info" class="button">查看账户资料</router-link>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import { EditPen, FolderChecked, Document } from '@element-plus/icons-vue'
import { useUserStore } from '@/stores/user'

// 直接用 userStore 的 username 字段
const userStore = useUserStore()
const displayUsername = computed(() => userStore.username || '未知用户')

// 路由路径统一为你的主路由
const menulist = ref([
  {
    path: '/compose',
    name: 'compose',
    label: '写邮件',
    icon: EditPen,
  },
  {
    path: '/inbox',
    name: 'inbox',
    label: '收件箱',
    icon: FolderChecked,
  },
  {
    path: '/draft',
    name: 'draft',
    label: '草稿箱',
    icon: Document,
  },
])

const defaultUserImg = ref('https://cube.elemecdn.com/0/88/03b0d39563f48251a9ed908f818141.png')
const ImgURL = ref(
  'https://upload-bbs.miyoushe.com/upload/2023/09/27/26454523/3ff0274b8a39b4c82f56034615cf7c7b_2534397800130338630.jpg',
)
const userImg = ref(ImgURL.value || defaultUserImg.value)
</script>

<style scoped>
.home-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  background-color: #f9f9f9;
  height: auto;
}

.profile {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.user-info {
  margin-right: 20px;
}

.avatar {
  border: #8b4b4b solid 3px;
}

.info p {
  margin: 0;
  font-size: 25px;
  color: #333;
  font-family: 'Courier New', Courier, monospace;
}

.menu {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  margin-bottom: 20px;
}

.fast-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: #333;
  padding: 10px;
  margin: 5px;
  border-radius: 5px;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition:
    background-color 0.3s,
    box-shadow 0.3s;
  font-size: 20px;
}

.fast-button:hover {
  background-color: #f0f0f0;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.fast-button el-icon {
  margin-bottom: 5px;
}

.account-assets {
  display: flex;
  justify-content: center;
}

.button {
  text-decoration: none;
  background-color: #d16053;
  color: white;
  padding: 10px 20px;
  border-radius: 5px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition:
    background-color 0.3s,
    box-shadow 0.3s;
  font-size: 20px;
  margin-bottom: 5px;
}

.button:hover {
  background-color: #b44c47;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
</style>
